package cn.aopmin.service;

import cn.aopmin.mapper.LogRecordMapper;
import cn.aopmin.pojo.LogRecord;
import jakarta.annotation.Resource;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.concurrent.ThreadPoolExecutor;

/**
 *
 * @author liuxm34
 * @since 2025/6/4
 */
@Service
public class BaseServiceImpl {

    @Resource
    private ThreadPoolTaskExecutor asyncTaskExecutor;
    @Resource
    private LogRecordMapper logRecordMapper;


    public void sendMessage(String message) {
        try {
            int i = 1 / 0;
        } catch (Exception e) {
            asyncTaskExecutor.execute(() -> {
             logRecordMapper.insert(LogRecord.builder()
                             .createTime( LocalDateTime.now())
                             .methodName(Thread.currentThread().getStackTrace()[1].getMethodName())
                             .requestParams(message)
                              .exception(e.getMessage())
                              .responseParams(null)
                              .requestTime(LocalDateTime.now())
                              .responseTime(LocalDateTime.now())
                     .build());
            });

        }
    }
}